package com.zmht.beike.web.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.zmht.beike.core.BaseAction;
import com.zmht.beike.po.TAimtocollection;
import com.zmht.beike.po.TCaiminfo;
import com.zmht.beike.po.TIaiminfo;
import com.zmht.specedu.vo.Teacher;
/**
 * 目标收藏
 * @author Administrator
 *
 */
public class AimToCollectionAction extends BaseAction {
	/**
	 * 收藏 目标 ajax 调用
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward conCaiminfo(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws Exception {
		String cid  = request.getParameter("id");
		String targetType = request.getParameter("targetType");
		Teacher teacher = (Teacher)request.getSession().getAttribute("current_user_session_key");
		
		
		TAimtocollection collection = new TAimtocollection(); 
		collection.setCollectionTeacherId(teacher.getTeacherId()+"");
		if("1".endsWith(targetType)){
			collection.setCaimId(cid);
			TCaiminfo caiminfo = this.getCaiminfoBiz().findById(new Integer(cid));
			collection.setOriginalTeacherId(caiminfo.getTeacherId()+"");
			caiminfo.setConcount(caiminfo.getConcount()+1);
			this.getCaiminfoBiz().updateCaiminfo(caiminfo);
		}else{
			collection.setIaimId(cid);
			TIaiminfo iaiminfo = this.getIaiminfoBiz().findById(new Integer(cid));
			collection.setOriginalTeacherId(iaiminfo.getTeacherId()+"");
			iaiminfo.setConcount(iaiminfo.getConcount()+1);
			this.getIaiminfoBiz().updateIaiminfo(iaiminfo);
			
		}
		//获得目标
		
		
		
		this.getAimToCollectionBiz().saveAimToCollection(collection);
		response.setCharacterEncoding("utf-8");
		java.io.PrintWriter out = response.getWriter();
		out.println("目标收藏成功！");
		out.close();
		return null;
	}
	
}
